package com.blyat.xsoft.gateway.context;

import reactor.core.publisher.Mono;
import reactor.util.context.Context;

/**
 * @Auther: syh
 * @Date: 2020/9/10
 * @Description:
 */
public class ReactiveXSoftContextHolder {

    public static <T> Context withXSoftContext(Class<T> clazz, Mono<T> exchange) {
        return Context.of(clazz, exchange);
    }

    public static <T> Mono<T> get(Class<T> clazz) {
        return Mono.subscriberContext()
                .filter(c -> c.hasKey(clazz))
                .flatMap(c -> c.<Mono<T>>get(clazz));
    }
}
